package com.lewis.module.m2.api.luck.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lewis.common.core.entity.BaseResult;
import com.lewis.module.m2.api.luck.mapper.LuckDayMapper;
import com.lewis.module.m2.api.luck.service.ILuckDayService;
import com.lewis.module.m2.api.luck.entity.Luck;
import com.lewis.module.m2.api.luck.entity.LuckDay;
import com.lewis.module.m2.api.luck.mapper.LuckMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 每日运势查询表 服务实现类
 * </p>
 *
 * @author lewis
 * @since 2021-12-01
 */
@Service
public class LuckDayServiceImpl extends ServiceImpl<LuckDayMapper, LuckDay> implements ILuckDayService {

	@Resource
	private LuckDayMapper luckDayMapper;

	@Resource
	private LuckMapper luckMapper;

	@Override
	public BaseResult getOneByCtimeAndQq(LuckDay luckDay) {
		LambdaQueryWrapper<LuckDay> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(LuckDay::getQq, luckDay.getQq());
		lambdaQueryWrapper.like(LuckDay::getCtime, luckDay.getCtime());
		LuckDay one = luckDayMapper.selectOne(lambdaQueryWrapper);
		if (one == null) {
			return BaseResult.fail().setMsg("今日并未进行抽签。");
		}
		Luck luck = luckMapper.selectById(one.getLuckId());
		List<String> list = new ArrayList<>();
		String sb =
				"今日运势：" + luck.getLevel() + "\n" +
				"运势评级：" + luck.getStar() + "\n" +
				"运势签文：" + luck.getSimple() + "\n" +
				"运势解签：" + luck.getContent();
		list.add(sb);
		return BaseResult.ok().setData(list);
	}
}
